Declare Function Fib (n as integer) as long 'Вычисление числа Фибоначи
Declare Function NOD (n1 as integer, n2 as integer) as integer 'НОД
Declare Function ExpandNumb (n as integer) as string 'Разложить число на простые множители
Declare Function Dig (n1 as integer, n2 as integer, count as integer) as string 'Деление с заданной точностью
Declare Function Fact (n as integer) as long 'Вычисление факториала (количество перестановок)
Declare Function Accom (n as integer, m as integer) as integer 'Число размещений из n элементов по m
Declare Function Comb (n as integer, m as integer) as integer 'Число сочетаний  из n элементов по m                      
Declare Function LaguerreCalc(n As Long, x As Double) As Double 'Расчет значения полинома Ляггера
Declare Function LaguerreSum(C() As Double, n As Long, x As Double) As Double 'Суммирование Ляггера по формуле Кленшоу


print "hello"
end

Function LaguerreSum(C() As Double, n As Long, x As Double) As Double
    Dim as Double r, b1, b2, i
    b1 = 0 : b2 = 0
    For i = n To 0 Step -1
        r = (2 * i + 1 - x) * b1/(i + 1) - ( i + 1) * b2 / (i + 2) + C(i)
        b2 = b1 : b1 = r
    Next i
    return r
End Function

Function LaguerreCalc(n As Long, x As Double) As Double
    Dim as Double r, a, b, i
    r = 1 : a = 1
    b = 1 - x
    If n = 1 then
        r = b
    End If
    i = 2
    Do While i <= n
        r = ((2 * i - 1 - x) * b -(i - 1) * a)/i
        a = b : b = r : i = i + 1
    Loop
    return r
End Function

Function Comb (n as integer, m as integer) as integer
  return Fact(n) / (Fact(n-m) * Fact(m)) 
End Function

Function Accom (n as integer, m as integer) as integer
  return (Fact(n) / Fact(n - m))
End Function

Function Fact(n as integer) as long
  dim as long p = 1
  if n = 0 then return 1
  for i as integer = 1 to n
    p *= i
  next
  return p
End Function

Function Dig (n1 as integer, n2 as integer, count as integer) as string
  Dim as string s
  Dim as integer f
  f = n1 \ n2
  s &= f & "."
  n1 = (n1 - f * n2) * 10
  for i as integer = 1 to count
    f = n1 \ n2 : s &= f
    n1 = (n1 - f * n2) * 10 
  next
  return s
End Function

Function ExpandNumb (n as integer) as string
  Dim as string s
  Dim as integer b, c
  
  do Until (n mod 2 <> 0)
    n = n\2
    s &= "2*"
  loop
  
  b = 3 
  c = sqr(n) + 1
  
  do while (b < c)
    if n mod b = 0 then 
      if n / b * b - n = 0 then
        s &= b & "*"
        n /= b : c = sqr(n) + 1
      else
        b += 2
      end if
    else
        b += 2
    end if
  loop
  
  s &= n  
  return s
End Function

Function NOD (n1 as integer, n2 as integer) as integer
  Dim as integer i, l
  Do Until (n2 = 0)
    i = int(n1/n2) : l = n2
    n2 = n1 - n2*i : n1 = l
  Loop
  return n1
End function

Function Fib (n as integer) as long
  Dim as Long i, a, b, c 
  if n = 0 then return 0
  if n > (-3) and n < 3 then return 1
  
  if n >= 3 then
    a = 0 : b = 1 
    for i = 0 to n
      c = a+b : a = b : b = c  
    next
  end if 
  if n <= -3 then c = -1^(n + 1) * Fib(-1 * n) 
  return c
End function